<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="140px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="序号" prop="sparepartsNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsNumber" placeholder="请填写序号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物料编码" prop="sparepartsCoding"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsCoding" placeholder="请填写物料编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="物料名称" prop="sparepartsName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsName" placeholder="请填写物料名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="规格型号" prop="sparepartsType"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsType" placeholder="请填写规格型号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="区分码使用" prop="sparepartsCodeUse"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsCodeUse" placeholder="请填写区分码使用"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单位" prop="sparepartsUnit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsUnit" placeholder="请填写单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="禁用说明" prop="sparepartsBanState"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsBanState" placeholder="请填写禁用说明"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="ABC分类" prop="sparepartsABCCategory"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsABCCategory" placeholder="请填写ABC分类"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="检斤物料误差范围" prop="sparepartsCheckAxe"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsCheckAxe" placeholder="请填写检斤物料误差范围"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="旧编码" prop="sparepartsUsedCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsUsedCode" placeholder="请填写旧编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="采购员" prop="sparepartsBuyer"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsBuyer" placeholder="请填写采购员"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="保管员" prop="sparepartsGuardian"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsGuardian" placeholder="请填写保管员"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="资料更新人" prop="sparepartsUpdater"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsUpdater" placeholder="请填写资料更新人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="资料更新日期" prop="sparepartsDateUpdate"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsDateUpdate" placeholder="请填写资料更新日期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否检斤物资" prop="sparepartsIfCheckAxe"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsIfCheckAxe" placeholder="请填写是否检斤物资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="是否以旧领新" prop="sparepartsIfOldchangenew"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsIfOldchangenew" placeholder="请填写是否以旧领新"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="库房报计划物资" prop="sparepartsPlanGoods"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsPlanGoods" placeholder="请填写库房报计划物资"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="使用部门" prop="sparepartsUserDepartment"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsUserDepartment" placeholder="请填写使用部门"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="采购提前期" prop="sparepartsAdvanceBuy"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsAdvanceBuy" placeholder="请填写采购提前期"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="电商编码" prop="sparepartsBusinessCode"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsBusinessCode" placeholder="请填写电商编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="导出时间" prop="sparepartsExportTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.sparepartsExportTime" placeholder="请填写导出时间"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          sparepartsNumber: '',
          sparepartsCoding: '',
          sparepartsName: '',
          sparepartsType: '',
          sparepartsCodeUse: '',
          sparepartsUnit: '',
          sparepartsBanState: '',
          sparepartsABCCategory: '',
          sparepartsCheckAxe: '',
          sparepartsUsedCode: '',
          sparepartsBuyer: '',
          sparepartsGuardian: '',
          sparepartsUpdater: '',
          sparepartsDateUpdate: '',
          sparepartsIfCheckAxe: '',
          sparepartsIfOldchangenew: '',
          sparepartsPlanGoods: '',
          sparepartsUserDepartment: '',
          sparepartsAdvanceBuy: '',
          sparepartsBusinessCode: '',
          sparepartsExportTime: '',
          remarks: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建表单`
        } else if (method === 'edit') {
          this.title = '修改表单'
        } else if (method === 'view') {
          this.title = '查看表单'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/spareparts/material/sparepartsMaterialCodeData/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.sparepartsMaterialCodeData)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/spareparts/material/sparepartsMaterialCodeData/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>
